/**
 * 
 */
package de.guidoludwig.jtm.server;

import java.util.List;

import javax.persistence.EntityManager;

import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;

import de.guidoludwig.jtm.domain.Archive;

/**
 * @author guido
 *
 */
public class ArchiveRepository extends AbstractRepository<Archive> {

	public ArchiveRepository() throws Exception {
		super(Archive.class);
	}

	@Override
	protected String[] getSearchFields() {
		return new String[] {"code", "name"};
	}

	public void reindex() {
		System.out.println("Indexing ARCHIVES" );
		EntityManager em = Server.getInstance().createEntityManager();
		FullTextEntityManager fullTextEntityManager = Search
				.getFullTextEntityManager(em);

		final List<Archive> entries = em.createQuery("select a from Archive a")
				.getResultList();
		for (Archive a : entries) {
			System.out.println("Indexing " + a.getName());
			fullTextEntityManager.index(a);
		}
		em.close();

	}

}